{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f0179f76",
   "metadata": {},
   "source": [
    "------\n",
    "* 日期：2022-10-12\\week08\n",
    "* 课程：python\n",
    "* 记录人：zhoubilian\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7fd07fc",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1.有序的数据结构-字符串\n",
    "\n",
    ">> 1. 字符串的基本概念（回顾）\n",
    ">>> 1. Single qutoes:'allows embedded \"double\"quotes'\n",
    ">>> 2. Double quotes:\"allows embedded\"quotes\"\n",
    ">>> 3. Triple quotes:\"\"Three single quotes\"\",\"\"Three double quotes\"\"\n",
    ">> 2. 字符串的性质和方法\n",
    "\n",
    "> 2. 有序的数据结构_列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a229fdf2",
   "metadata": {},
   "source": [
    "# 1.字符串的性质和方法\n",
    "\n",
    "* 字符串的性质\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    ">> 1. 使用len()检查字符串的长度\n",
    "* 字符串的基础方法（运算法则）\n",
    "> 1. 字符串的取值：str[index]\n",
    "> 2. 字符串的切片：str[start,stop],stop取不到\n",
    "> 3. 字符串的拼接：+\n",
    "> 4.in检查成员是否存在\n",
    "* 字符串的一般方法（Function/Methods 函数/方法）\n",
    "> 1. isdigit()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "98d9c4dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "96b69856",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3073f64b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c78e87e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2f0a6a42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'方'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3a321c34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "37b91178",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]+text[1]+text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4d03d5a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]# 等价于text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "7b72cc2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "932c03a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "6efff7de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6bb25c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "* in检查成员对象\n",
    "* count()检查字符串出现的次数 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a615ba92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d4f1a03a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"北京\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "d0259080",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93824699",
   "metadata": {},
   "source": [
    "* isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "49e94038",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1=19\n",
    "age_2=\"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "034bf41a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "12fb56b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1+int(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "f22b6504",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_1+int(age_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6862e38d",
   "metadata": {},
   "source": [
    "# 2.有序的数据结构_列表（List）\n",
    "\n",
    "* 1. 列表的概念和基本性质\n",
    ">> 1. Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.\n",
    "\n",
    "* 2. 列表一般方法(如何学习)\n",
    "> 1. 使用.Tab键查看列表的方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d89f53d0",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符串进行操作，列表是对items元素进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "7460b6da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " # 列表的形式\n",
    "squares = [1, 4, 9, 16, 25] # 列表里面放数值\n",
    "squares   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "69e883ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "a3eda90f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "1dc5358f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"Alex\",\"Marry\",\"Jan\"] # 列表里面放字符\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "06092b5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.count(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "0b99949e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"Jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "b03da709",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "3c927b0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "50bf4257",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Marry']"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names [1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "9495e3ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jan']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "8b517a44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan']"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "544f15b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'Marry']"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出 \"Jack\",\"Marry\"用切片的方法\n",
    "names[:3:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "56e015d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'Alex', 'Marry']"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7775c87d",
   "metadata": {},
   "source": [
    "* 2. 列表一般方法(如何学习)\n",
    "> 1. 增加\n",
    "> 2. 删除\n",
    "> 3. 改\n",
    "> 4. 查：in\n",
    "* 列表的学习方法(步骤)\n",
    "> 1. 使用.Tab键查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "602b35b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"Alex\",\"Marry\",\"Jan\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "a828a065",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (1108101500.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [62]\u001b[1;36m\u001b[0m\n\u001b[1;33m    names.\u001b[0m\n\u001b[1;37m          ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "names."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "fba00609",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "646301a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "f9989e38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a01d96b3",
   "metadata": {},
   "source": [
    "# 课后作业\n",
    "* 列表的方法尝试所有的方法\n",
    "* 总结列表的方法学习心得（表格形式总结）"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
